<template>
  <div>
    <h1>添加广告</h1>
    <p>图片<input type="file" id="pic" @change="post_img"></p>
    <p>地址<input type="text" v-model="from.site"></p>
    <p>类型<input type="text" v-model="from.type"></p>
    <button @click="post_adv">添加</button>
  </div>
</template>

<script>
export default {
  name: "add_adv",
  data(){
    return{
      from:{}
    }
  },
  methods:{
    post_img(){
      let img = document.getElementById('pic').files[0]
      this.from.picture=img
    },
    post_adv(){
      let fromdata = new FormData()
      fromdata.append('picture',this.from.picture)
      fromdata.append('site',this.from.site)
      fromdata.append('type',this.from.type)
      this.$axios.post('users/adv/',fromdata).then(res=>{
        if(res.data.code==200){
          alert('添加成功')
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
